﻿using Sunny.UI;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using WINPE_TOOLBOX.InstallPage;
using WINPE_TOOLBOX.MainPage;
using WINPE_TOOLBOX.ModuleManger;
using WINPE_TOOLBOX.Page;
using static WINPE_TOOLBOX.ReadOnlyConfig;

namespace WINPE_TOOLBOX
{
    public partial class Form1 : UIAsideMainFrame
    {
        public Form1()
        {
            InitializeComponent();
            //设置关联
            Aside.TabControl = MainTabControl;
            int pageindex = 1000;
            AddPage(new FirstPage(),pageindex);
            //设置Header节点索引
            TreeNode parent =  Aside.CreateNode("首页",57460,24,pageindex);

            pageindex = 2000;
            parent = Aside.CreateNode("安装", 560273,24,pageindex);

            //设置子菜单
            Aside.CreateChildNode(parent,AddPage(new InstalltoLocal(),++pageindex));
            Aside.CreateChildNode(parent,AddPage(new InstalltoUSB(),++pageindex));
            Aside.CreateChildNode(parent, AddPage(new MakeISO(),++pageindex));

            pageindex = 3000;
            parent = Aside.CreateNode("模块", 559632,24,pageindex);
            Aside.CreateChildNode(parent, AddPage(new ModuleDown(),++pageindex));
            Aside.CreateChildNode(parent, AddPage(new ManagerModule(), ++pageindex));
            Aside.CreateChildNode(parent, AddPage(new TaskManager(), ++pageindex));

            pageindex = 4000;
            AddPage(new SettingPage(),pageindex);
            Aside.CreateNode("设置",559577,24,pageindex);

            pageindex = 5000;
            AddPage(new AboutPage(),pageindex);
            Aside.CreateNode("关于", 560313,24,pageindex);

          
            //显示默认界面
            Aside.SelectFirst();
            Aside.ExpandAll();
            
        }

        private async void Form1_Load(object sender, EventArgs e)
        {
            await initAsync();
            initDir();
            Check.CheckBootMode();
        }
        //创建目录，运行所需的
        private void initDir()
        {
            ResourcePathConfig _resource = new ResourcePathConfig();
            Utils.MakeDir(_resource.ClientTemp);
            Utils.MakeDir(_resource.Client);
            Utils.MakeDir(_resource.Pe);
        }

        private async Task initAsync()
        {
            if (await Check.IsInternetConnectedAsync())
            {
                this.ShowSuccessNotifier("网络连接正常！");
            }
            else
            {
                this.ShowErrorNotifier("网络连接异常，功能将首先");
            }
        }

        private void button1_Click_1(object sender, EventArgs e)
        {
            if (Aside.Width >100)
            {
                Aside.Width = this.Aside.Width - 139;
            }
            else
            {
                Aside.Width = 195;
            }
            test test1 = new test();
            test1.Show();
            
        }

        private void Aside_Resize(object sender, EventArgs e)
        {
            if (Aside.Width < 100)
            {
                Aside.CollapseAll();
                
            }
            else
            {
                Aside.ExpandAll();

            }
        }
    }
}
